(function(window) {

	var pf = {
		pages: {},
		curPage: '',
		overlayPage: [],
		$operate: null,
		series: [],
		lines: []
	};

	//c点击调用通道1
	pf.onControlClick = function(data) {
		var $page = pcc2.$pages.find('#' + data.pageID);
		// alert(data.pageID);点击后调用
		switch (data.type) {
			case 'test-drive':
				var url = data.url;
				if(url)
					kpi.store('books', url.substr(url.indexOf('#/book/') + '#/book/'.length));
				return;
				break;
			// 控制端点击content中的按钮
			case 'content-btn':
				(function() {
					if (data.pageID.indexOf('show') > -1) {
						// 这里是show（）；
						$page.children('.content').find('.right-zone .so-btn').eq(data.index).click();
					} else if (data.pageID.indexOf('detail') > -1) {
						if (data.index == "playvideo") {
							$page.find('.video_play').click();
						} else {
								$page.children('.content').find('.buttonWrap .so-btn').eq(data.index).click();
						}
					} else if (data.pageID == 'image') {
						if (data.index=="book_test") {
							// alert(1);
						}else{
							$page.children('.content').find('.model_center .so-btn').eq(data.index).click();
						}
					} else if (data.pageID == 'topic') {
						if (data.index=="go_home") {
							pf.goPage('show', {showID: 'wdy'});
						}else if (data.index=="display_cars") {
							pf.goPage('show', {showID: 'display_cars'});
						}else{
							$page.children('.content').find('.model_center .so-btn').eq(data.index).click();
						}
					}else if (data.pageID == 'play_video') {
						if (data.index=="video_close") {
							if (pf.overlayPage=="play_video") {
								$(".icon-btn.sprite.close_b").click();
							};
						}
					} else if (data.pageID == 'features') {
						if (data.index=="book_test") {
							// alert(1);
						}else if (data.index == "arrow_left_white") {
							$page.find('.features_button.hi-icon').eq(0).click();
						} else {
							$page.find('.features_button.hi-icon').eq(1).click();
						}
						pf.emitPage($("#features"));
					} else if (data.pageID == "vehicle_small_List") {
						if (data.index == 'List_left') {
							$page.find('.ehicle_center_car.hi-icon.hi-icon-mobile.cars_left').click();
							pf.emitPage($("#vehicle_small_List"));
						}else if (data.index == 'List_right') {
							$page.find('.ehicle_center_car.hi-icon.hi-icon-mobile.cars_right').click();
							pf.emitPage($("#vehicle_small_List"));
						}else{
							$page.find('.cars').eq(data.index).click();
						}
					} else if (data.pageID == "vehicleList") {
						$page.find('.cars.porsche_image').eq(data.index).click();
					} else if (data.pageID == 'movie') {
						switch(data.move_name)
						{
						case "zhanglei":
							data.index=3;
						  break;
						case "zhou":
							data.index=4;
						  break;
						case "walter_vid":
							data.index=5;
						  break;
						default:
						}
						// alert(data.move_name);
						$("#play_video").attr("video_name",data.move_name);
						$page.find('.video_image_play').eq(data.index).click();
					}
				})();
				break;
			case 'bottom-btn':
				// if (data.pageID="play_video") {
				// 		pcc2.video_close_detail();
				// };
				if(data.index == "lang-btn") {
					$page.find('.lang-btn').click();
				}
				if(data.index == 'pdf_close') {
					$('#viewerContainer').find(".icon-wrap").click();
					pf.emitPage($("#detail"));
				} else {
					pf.$operate.find('.icon-wrap').eq(data.index).click();
				}
				break;
		}
	};
	pf.head_type=function(action){
		var type="text";
		switch(action){
			case "911":
			case "boxster":
			case "cayman":
			case "macan":
			case "cayenne":
			case "panamera":
			type="image";
			break;
			default:
			type="text";
			break;
		}
		return type;
	}
	/**
	 * 传递页面数据到控制端
	 * @param  {$dom} $page 页面jQuery元素
	 */
	//客户发给c
	pf.emitPage = function($page) {

		if(pcc2.isHand || !pcc2.connected)
			return;

		var $head_tppe=pf.head_type($page.attr("page_show"));
		// data = {
		// 	page: '',
		// 	content: [
		// 		{
		// 			type: icon,
		// 			img:  ,
		// 			txt:  ,
		// 		}
		// 	]
		// };

		var data = {
			pageID:  '',
			content: [],
			bottom:  [],
			lang:    i18n.getLang()
		};

		// CONTENT
		var isShowPage   = $page.find('.page-show').length > 0;
		var isDetailPage = $page.find('.page-detail').length > 0;
		var isTopic      = $page.find('.page-detail').length > 0;

		var pageID = data.pageID = $page.attr('id');
		var PAGE   = pf.pages[pageID];
		var key_lang=$page.find(".title").find("span").attr("data-langkey");

		// alert(pageID);
		// show page
		if (isShowPage) {
			var $items = $page.find('.right-zone .so-btn');
			$items.each(function() {
				var icon = {};
				if ((key_lang!=="sport")&&(key_lang!=="family")&&(key_lang!=="what")) {
					icon = {
						type: 'icon',
						img: $(this).find('.icon-btn').data('name'),
						index: $(this).index(),
						txt: $(this).find('.sub-title .i18n-word').html(),
						title:{big_title:$page.find(".title").find("span").attr("data-langkey")+"_line",type:"text",small_title:"golf"}
					};
				}else if(key_lang=="display_cars"){
					alert('display_cars');
				}else{
					icon = {
						type: 'icon',
						img: $(this).find('.icon-btn').data('name'),
						index: $(this).index(),
						txt: $(this).find('.sub-title .i18n-word').html(),
						title:""
					};
				}
				data.content.push(icon);
			});
		}
		// detail page
		if (isDetailPage) {
			var $items = $page.find('.buttonWrap .so-btn');
			if ($('#detail').find('.videoImgWrap').find("img").length == 0) {
				data.content.push({
					type: 'icon',
					img: 'car_watch_video',
					index: 'playvideo',
					txt: __("watch_video"),
					title: {big_title:$('#detail').attr("page_show"),type:$head_tppe,small_title:$('#detail').attr("page_show")+"_title2"}
				});
			};
			$items.each(function() {
				var icon = {
					type: 'icon',
					img: $(this).data('name'),
					index: $(this).index(),
					txt: $(this).find('.txt .i18n-word').html(),
					title: {big_title:$('#detail').attr("page_show"),type:$head_tppe,small_title:$('#detail').attr("page_show")+"_title2"}
				};

				if(icon.img == 'test_drive_r') {
					icon.url = config.bookUrl + $page.attr('page_show');
				}

				data.content.push(icon);
			});
		}
		if (pageID == 'viewerContainer') {
			data.content.push({
					type: '',
					img: '',
					index: '',
					txt: '',
					title:''
					});
		}
		if (pageID == 'image') {
			if ($page.find('.testdrive').css("display")=="block") {
					data.content.push({
						type: 'icon',
						img: 'test_drive_r',
						index: 'book_test',
						txt: __('book_test'),
						title:''
					});
			};
		}
		if (pageID == 'features') {
			var $items = $page.find('.features_button.hi-icon');
			if ($(".features_button_right.hi-icon.hi-icon-mobile.features_button.porsche_image").css("opacity")!=="1") {
					data.content.push({
					type:  'icon',
					img:   'car_test_drive_white',
					url:   config.bookUrl + PAGE.car,
					index: 'book_test',
					txt:   __("book_test_features"),
					title: {big_title:"Book_a_Drive",type:$head_tppe,small_title:$page.find('.features_center_iscroll1_big_tittle.tittle_features_big.font-motorsport').text()}
					});
			}
			$items.each(function() {
				var icon = {
					type:   'icon',
					img:    $(this).data('name'),
					index:  $(this).data('name'),
					txt:    "",
					// txt: $(this).data('text'),
					title:  {big_title:$page.find('.features_center_iscroll1_big_tittle.tittle_features_big.font-motorsport').text(),type:$head_tppe,small_title:"technical_specs"}
				};
				if ($(this).css("opacity")=="1") {
					data.content.push(icon);
				};
			});
		}
		// topic page
		if (pageID == 'topic') {
			var $items = $page.find('.model_center .so-btn');
			data.content.push({
					type: 'icon',
					img: 'display_light',
					index: 'display_cars',
					txt: __("display_cars"),
					title:''
			});
			data.content.push({
					type: 'icon',
					img: 'home_icon_w_border',
					index: 'go_home',
					txt: __("what_in_line"),
					title:''
			});
			$items.each(function() {
				var icon = {
					type: 'icon',
					img: $(this).find('.icon-btn').data('name'),
					index: $(this).index(),
					txt: $(this).find('.sub-title .i18n-word').html(),
					title:{big_title:"select_topic",type:"text",small_title:""}
				};
				data.content.push(icon);
			});
		}
		//vehicle_small_List
		if (pageID == 'vehicle_small_List') {
			var $items = $page.find('.vehicle_small_List_page .cars');
			var $mun=$(".ehicle_center_car.hi-icon.hi-icon-mobile.cars_right");
			$items.each(function() {
				var icon = {
					type: 'icon',
					img: "stocklist_" + $(this).attr('cars_name'),
					index: $(this).index(),
					txt: $(this).find('.cars_tittle').html(),
					title:""
				};
				data.content.push(icon);
			});
			if ($(".ehicle_center_car.hi-icon.hi-icon-mobile.cars_left").css("opacity")!=="0") {
				data.content.push({
					type: 'icon',
					img: 'arrow_left_black',
					index: 'List_left',
					txt: '',
					title:""
				});
			};
			if (($mun.css("display")!=="none")) {
				if (($mun.css("opacity")!=="0")) {
				data.content.push({
					type: 'icon',
					img: 'arrow_right_black',
					index: 'List_right',
					txt: '',
					title:""
				});
				};
			};
			// alert(1);
		}
		if (pageID == 'play_video') {
				data.content.push({
					type: 'icon',
					img: 'close_b',
					index: 'video_close',
					txt: __("close"),
					title:  {big_title:$("#play_video").attr("video_name"),type:"text",small_title:""}
				});
		}
		//vehicleList
		if (pageID == 'vehicleList') {
			var $items = $page.find('.cars.porsche_image');
			$items.each(function() {
				var icon = {
					type: 'icon',
					img: "stocklist_" + $(this).attr('car_name'),
					index: $(this).index(),
					txt: $(this).find('.overview-title').html(),
					title:""
				};
				data.content.push(icon);
			});
		}
		//movie
		if (pageID == 'movie') {
			var $items = $page.find('.video_number');
			$items.each(function() {
				var icon = {
					type: 'icon',
					img: "car_watch_video",
					index: $(this).index(),
					txt: $(this).find('.video_name').html(),
					title:""
				};
				data.content.push(icon);
			});
		}
		// bottom
		var $items = pf.$operate.find('.icon-wrap:visible');
			if (pageID == 'play_video') {
				data.bottom.push({
					type: '',
					img: '',
					index: '',
					txt: '',
					title:""
				});
			}else if (pageID == 'viewerContainer') {
				data.bottom.push({
					type: 'icon',
					img: 'close_b',
					index: 'pdf_close',
					txt: '',
					title:""
				});
			}else{
				$items.each(function() {
					var icon = {
						type: 'icon',
						img: $(this).data('name'),
						index: $(this).index(),
						txt: '',
						title:""
					};
					data.bottom.push(icon);
				});
			}
			if(pageID == 'topic'){
				// data.bottom.push({
				// 	type:  'icon',
				// 	img:   i18n.getLang() == 'en' ? 'chinese_lang_w' : 'english_lang_w',
				// 	index: 'lang-btn',
				// 	txt:   __("langbtn"),
				// 	title: ''
				// });
			}
		console.warn(data, 'send to lily');

		pcc2.so.emit('onPage', data);
	};

	// 存储页面跳转数据
	pf.storeToLine = function(flag, pageID, params) {
		if (flag == 'goPage') {
			pf.lines.push({
				flag: flag,
				pageID: pageID.replace('-', ''),
				params: $.extend(true, {}, params)
			});
		}
	};

	// 渲染return btn
	pf.renderBackBtn = function() {
		var lines = pf.lines;
		var len = lines.length;
		var last = lines[len - 1];
		var llast = lines[len - 2];

		// 有上一个
		if (last && llast) {
			// 不是在wdy页面
			if (last.params.showID != 'wdy') {
				return pf.showBackBtn();
			}
		}
		pf.hideBackBtn();
	};

	// Go Back
	pf.goBack = function() {
		var lines = pf.lines;
		var last = lines.pop();
		var llast = lines.pop();
		if (llast) {
			if (llast.pageID=="show") {
				if (llast.params.showID=="display_cars") {
					// alert("pf 450");
				};
			};
			pf.goPage(llast.pageID, _.extend({
				isBack: true
			}, llast.params));
		}
	};

	var $btnWrapper = null;

	pf.initPDF = function() {
		var url = './catalog.pdf';
		PDFJS.getDocument(url).then(function getPdfHelloWorld(pdf) {
			//
			// Fetch the first page
			//
			pdf.getPage(1).then(function getPageHelloWorld(page) {
				var scale = 1.5;
				var viewport = page.getViewport(scale);

				//
				// Prepare canvas using PDF page dimensions
				//
				var canvas = document.getElementById('the-canvas');
				var context = canvas.getContext('2d');
				canvas.height = viewport.height;
				canvas.width = viewport.width;

				//
				// Render PDF page into canvas context
				//
				var renderContext = {
					canvasContext: context,
					viewport: viewport
				};
				page.render(renderContext);
			});
		});
	};

	/**
	 * 页面管理类初始化
	 */
	pf.init = function() {
		pf.$operate = pcc2.$c.find('.operate-zoon');
		$btnWrapper = pf.$operate.find('.btns-wrapper ');

		for (var i in pf.pages) {
			pf.pages[i].init();
		}

		initBottom();
		// pf.initPDF();
		// rside.init();

		// EVENT
		// pf.$operate.on('click', '.btn', function() {
		// 	var flag = $(this).data('flag');
		// 	operateEvent(flag, $(this));
		// });
		// pcc2.$pages.on('click', '.page', function() {
		// 	if(!$menu.hasClass('overlay'))
		// 		hideRightBottom();
		// });

		pcc2.$pages.on('click', '.lang-btn', function() {
			pcc2.switchLang();
			if (pf.overlayPage=="topic") {
				pf.emitPage($("#topic"));
			};
		});
	};

	pf.showBackBtn = function() {
		pf.$operate.find('.icon-btn.return_b').show();
		pf.$operate.find('.liao_css3.return_b').show();
	};
	pf.hideBackBtn = function() {
		pf.$operate.find('.icon-btn.return_b').hide();
		pf.$operate.find('.liao_css3.return_b').hide();
	};

	/**
	 * 创建新页面
	 * @param  {string} pageID 页面标识
	 * @return {object}        page实例化
	 */
	pf.newPage = function(pageID, nolayout) {
		return pf.pages[pageID] = new Page(pageID, nolayout);
	};

	/**
	 * 得到当前页面的ID
	 * @return {string} 页面ID
	 */
	pf.getActivePage = function() {
		return pf.curPage;
	};

	/**
	 * 修改页面background image
	 * @param  {string} page bg ID
	 */
	pf.changeBg = function($page, pageID, flagID) {
		var map = {
			'wdy': 'wdy_bg.jpg',
			'family': 'family_bg.jpg',
			'cupasia': 'cupasia_bg.jpg',
			'events': 'events_bg.jpg',
			'pcpuxi': 'pcpuxi_bg.jpg',
			'stock': 'stock_bg.jpg',
			'model_general': 'model_general_bg.jpg',
			'welcome': 'welcome_bg.jpg',
			'topic': 'black_bg.jpg'
		};

		var item = map[flagID] || map[pageID] || map['model_general'];
		$page.css('background-image', 'url(./image/bg/' + item + ')');
	};

	/**
	 * 以overlay形式展示页面
	 * @param  {string} pageID 页面ID
	 * @param  {object} params 传递参数数组
	 */
	pf.overlay = function(pageID, params) {
		if (pageID=="features") {
			$('.operate-zoon').addClass("test_drive_b_show");
		}else if(pageID=="play_video") {
			$('.operate-zoon').addClass("test_drive_b_show");
		}else{
			$('.operate-zoon').removeClass("test_drive_b_show");
		}

		var ps = pf.pages;
		params = params || {};
		if (pf.curPage != pageID && ps[pageID]) {
			// hideOverlay();

			pf.storeToLine('overlay', pageID, params);

			// kpi
			kpi.store('pages', params.showID || params.detailID || pageID);

			pf.overlayPage.push(pageID);
			ps[pageID]['onShow'] && ps[pageID]['onShow'](params);
			ps[pageID].$el.css('z-index', 3 + pf.overlayPage.length).show();
			pf.changeBg(ps[pageID].$el, pageID, params.showID || params.detailID || '');

			// effect.overlay();
			effect.pt(pageID == 'topic' ? 33 : 13, ps[pf.curPage] && ps[pf.curPage].$el, ps[pageID].$el);

			ps[pageID].$el.addClass('overlay');
			overlayBottom();

			pf.emitPage(ps[pageID].$el);
			// rside.show(params.notJump);
		}
	};

	var hideOverlay = pf.hideOverlay = function(pageID, params) {
		var ps = pf.pages;
		var oldid = pf.overlayPage.pop();
		var nowid = _.last(pf.overlayPage) || pf.curPage;
		if (oldid=="features") {
			$('.operate-zoon').removeClass("test_drive_b_show");
		}
		if (oldid=="play_video") {
			$('body').removeClass('wdy');
			$('.operate-zoon').removeClass("test_drive_b_show");
		}
		if (oldid=="topic") {
			if (nowid=="show") {
				if ($("body").hasClass("wdy")) {
					$('.operate-zoon').addClass("test_drive_b_show");
				};
			}else{
				$('.operate-zoon').removeClass("test_drive_b_show");
			}
		}
		if(oldid=="image"){
			if ($("body").hasClass("wdy")) {
				$('.operate-zoon').addClass("test_drive_b_show");
			};
		}

				// pcc2.light('off');

		var cb = function() {
			ps[oldid] && ps[oldid]['onHide'] && ps[oldid]['onHide']();
			ps[oldid] && ps[oldid].$el.removeClass('overlay').css('z-index', 1).hide();
			normalBottom();

			pf.emitPage(ps[nowid].$el);
		};

		if (ps[nowid]) {
			// if(pageID == 'testDrive')
			// 	pf.pages.testDrive.$keyboard.hide();
			effect.pt(oldid == 'topic' ? 34 : 12, ps[oldid].$el, ps[nowid].$el, cb);
		}
	};

	/**
	 * 检查goPage方法是否应该调用overlay
	 * @return {boolean} 是否调用
	 */
	var checkOverlay = function() {
		if (pf.overlayPage && pf.overlayPage.length > 0) {
			return true;
		} else
			return false;
	};

	/**
	 * 跳转页面
	 * @param  {string} pageID 跳转页面的ID
	 * @param  {object} params 传递到新页面的参数
	 * @return {boolean}        是否跳转成功
	 */
	pf.goPage = function(pageID, params) {
		var ps = pf.pages;
		params = params || {};
		if (pageID == 'detail') {
			pageID = (pf.curPage == 'detail') ? '-detail' : 'detail';
		}
		if (pageID == 'show') {
			pageID = (pf.curPage == 'show') ? '-show' : 'show';
		}

		if (params.showID == 'wdy') {
			pf.$operate.find('.home_icon').hide();
			$("#container").addClass('wdy');
			$('.operate-zoon').addClass("test_drive_b_show");
		} else {
			pf.$operate.find('.home_icon').show();
			$("#container").removeClass('wdy');
			$('.operate-zoon').removeClass("test_drive_b_show");
		}

		// if((pf.curPage!=pageID || params.isBack || params.isHome) && ps[pageID]) {
		if ((pf.curPage != pageID || params.force) && ps[pageID]) {

			var oldid = pf.curPage;
			pf.curPage = pageID;

			pf.hideBackBtn();
			pf.storeToLine('goPage', pageID, params);
			pf.renderBackBtn();

			// kpi
			kpi.store('pages', params.showID || params.detailID || pageID);

			// effect 执行前显示dom
			ps[oldid] && ps[oldid].$el.show();
			ps[pageID] && ps[pageID].$el.show();
			pf.changeBg(ps[pageID].$el, pageID, params.showID || params.detailID || '');
			ps[pageID] && ps[pageID]['onShow'] && ps[pageID]['onShow'](params);

			var cb = function() {
				ps[oldid] && ps[oldid].$el.hide();
				ps[oldid] && ps[oldid]['onHide'] && ps[oldid]['onHide']();

				if (pcc2.connected) {
					pf.emitPage(ps[pageID].$el);
				}
			};

			if (checkOverlay()) {
				cb && cb();
				pf.hideOverlay();
			} else {
				effect.pt(params.isBack ? 14 : 15, ps[oldid] && ps[oldid].$el, ps[pageID] && ps[pageID].$el, cb);
			}
			return true;
		} else
			return false;
	};

	// pf.icons = function($el, btns) {
	// 	if(typeof btns == 'string')
	// 		btns = [btns];
	// 	var tpl  = '<div data-name="%s" class="icon-btn sprite %s"> </div>';
	// 	var html = '';
	// 	_.each(btns, function(v, k) {
	// 		html += util.format(tpl, v, v);
	// 	});
	// 	$el.html(html);
	// };

	/*------- RIGHT SIDE EVENT ------- START -------*/
	var rside = pf.rside = {
		list: {},
		$dom: null,
		$btns: null
	};
	rside.init = function() {
		var list = rside.list;
		var $dom = rside.$dom = pcc2.$c.find('.right-side-zone');
		pcc2.$pages.children('.page').each(function() {
			var pageID = $(this).attr('id');
			var $r = $(this).find('.iscroll_leave').addClass('rside_' + pageID);
			$r.children().addClass('right-side-btn');
			$r.appendTo($dom);
		});

		$dom.find('.right-side-btn:not(.active)').on('click', function() {
			(function(i, $dom) {
				rside.active(i, $dom);
			})($(this).index(), rside.$btns);
		});
	};
	rside.show = function(notJump) {
		var pageID = pf.getActivePage();
		if (!notJump) {
			var $btns = rside.$dom.children().hide().filter('.rside_' + pageID).show();
			window.setTimeout(function() {
				rside.$btns = $btns;
			}, 100);
			(function(i, $dom) {
				rside.active(i, $dom);
			})(0, $btns);
		}
	};
	rside.getDom = function(pageID) {
		return rside.$dom.children().filter('.rside_' + pageID);
	};
	rside.active = function(redNum, $btns) {
		$btns.children('.right-side-btn').removeClass('active').eq(redNum || 0).addClass('active');
	};

	/*------- RIGHT SIDE EVENT ------- END -------*/

	/*------- BOTTOM EVENT ------- START -------*/
	var $bRight = null;
	var $bMid = null;
	var $menu = null;

	var operateEvent = function(flag, $dom) {
		switch (flag) {
			case 'tohome':
				pf.goPage('home', {
					isHome: true
				});
				break;
			case 'dealership':
				pf.goPage('dealership');
				break;
			case 'about':
				// pf.goPage("principle");
				pf.goPage('detail', {
					detailID: 'principle'
				});
				break;
			case 'switch':
				if ($menu.hasClass('overlay')) {
					hideOverlay();
				} else if ($menu.hasClass('close'))
					hideRightBottom();
				else
					showRightBottom();
				break;
			case 'switchlang':
				// var lang = i18n.getLang();
				// i18n.setLang(lang == 'en' ? 'zh-cn' : 'en');
				// pcc2.$c.find('.i18n-word').each(function() {
				// 	var k = $(this).data('langkey');
				// 	$(this).replaceWith(i18n.get(k));
				// });
				break;
			case 'motorsport':
				pf.goPage("Racing");
				break;
			case 'service':
				pf.goPage("service");
				break;
			case 'experience':
				pf.goPage("exp");
				break;
			case 'prev':
			case 'back':
			case 'next':
				if ($dom.data('disable') != 'yes') {
					var pageID = pf.getActivePage();
					var ps = pf.pages;
					ps[pageID]['onMidEvent'] && ps[pageID]['onMidEvent'](flag);
				}
				break;
		}
	};

	var overlayBottom = function() {
		pf.$operate.addClass('overlay');
		// $bRight.hide();
		// $menu.addClass('close overlay');
	};
	var normalBottom = function() {
		if (pf.overlayPage.length <= 0)
			pf.$operate.removeClass('overlay');
	};
	var getPageIDFromSeries = function(series) {
		var array = series.split('-');
		return array[0] || series;
	};
	var initBottom = function() {
		// icons.render(pf.$operate, ['menu_burger_btn', 'close_b']);
		icons.render(pf.$operate, [{
			name: 'home_icon'
		}, {
			name: 'return_b'
		}, {
			name: 'test_drive_b'
		}, {
			name: 'menu_burger_btn'
		}, {
			name: 'close_b'
		}]);

		pf.$operate.find('.home_icon.icon-btn').parents('.icon-wrap').css('float', 'left');

		// $bRight = $btnWrapper.filter('.fr');
		// $bMid   = $btnWrapper.filter('.mid');
		// $menu   = pf.$operate.find('.btn.switch');

		// $bRight.children('.btn').on('click', function(e) {
		// 	$bRight.children('.btn').removeClass('active');
		// 	$(this).addClass('active');

		// 	hideRightBottom();
		// }).each(function() {
		// 	var flag = $(this).data('flag');
		// 	$(this).find('.txt').html(__('btn_'+flag));
		// });
	};
	var resetBottom = function(pageID) {
		return false;
	}
	var hideRightBottom = function() {
		$bRight.slideUp('fast');
		$menu.removeClass('close');
	};
	var showRightBottom = function() {
		$bRight.slideDown('fast');
		$menu.addClass('close');
	};

	var hideMidBottom = function() {
		// $bMid.slideUp('fast');
	};
	var showMidBottom = function() {
		// $bMid.slideDown('fast');
	};
	var setMid = function(left, mid, right) {
		// v = 0 不显示
		// v = 1 半透明无法点击
		// v = 2 正常显示

		var arg = arguments;
		$bMid.children('.btn').each(function(index) {
			if (!isNaN(arg[index])) {
				$(this).css('opacity', [0, 0.5, 1][arg[index]]).data('disable', ['yes', 'yes', 'no'][arg[index]]);
				if (arg[index] == 0)
					$(this).hide();
				else
					$(this).show();
			}
		});
	};


	/*------- BOTTOM EVENT ------- START -------*/


	/*------- SERIES ------- START -------*/
	var seriesL = pf.series;
	var storeSeries = function(seriesNumber) {
		seriesL.push(seriesNumber);
		resetBottom();
	};
	var popSeries = function() {
		seriesL.pop();
		return getSeries();
	};
	var getSeries = function() {
		return _.last(seriesL);
	};
	/*------- SERIES ------- END -------*/


	/*------- PAGE CLASS ------- START -------*/
	var Page = function(pageID, nolayout) {
		this.id = pageID;
		this.nolayout = nolayout || false;
		this.$el = null;
	};
	Page.prototype.init = function() {
		var tpl = pcc2.getTpl('page_' + this.id.replace('-', ''));
		var baseTpl = pcc2.getTpl('page_base');
		if (tpl) {
			tpl = _.template(tpl, {});
			var html = _.template(baseTpl, {
				pageID: this.id,
				content: tpl,
				nolayout: this.nolayout
			});
			this.$el = $(html);
			pcc2.$c.children('.pages').prepend(this.$el);

		} else {
			console.log('init empty page ' + this.id);
		}

		this.onCreate && this.onCreate();
	};
	Page.prototype.isActive = function() {
		return this.id == pf.getActivePage();
	};
	Page.prototype.triggerEvent = function(flag) {
		switch (flag) {
			case 'close':
				if ($menu.hasClass('close'))
					$menu.click();
				break;
		}
	};

	// 一下为每个page应该实现的方法
	Page.prototype.onCreate = function() {};
	Page.prototype.onShow = function() {};
	Page.prototype.onHide = function() {};
	Page.prototype.onMidEvent = function() {};
	/*------- PAGE CLASS ------- END -------*/

	pf.storeSeries = storeSeries;
	pf.getSeries = getSeries;
	pf.showMidBottom = showMidBottom;
	pf.setMid = setMid;
	window.pageFactory = window.pf = pf;

})(window);